home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / ixemul-complete / ixemul / library / misc.c < prev    next >
C/C++ Source or Header  |  1996-08-13  |  4KB  |  197 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *  Portions Copyright (C) 1994 Rafael W. Luebbert
  5.  *  Portions Copyright (C) 1996 Jeff Shepherd
  6.  *
  7.  *  This library is free software; you can redistribute it and/or
  8.  *  modify it under the terms of the GNU Library General Public
  9.  *  License as published by the Free Software Foundation; either
  10.  *  version 2 of the License, or (at your option) any later version.
  11.  *
  12.  *  This library is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  *  Library General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU Library General Public
  18.  *  License along with this library; if not, write to the Free
  19.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  */
  21.  
  22. /* Miscellaneous functions */
  23.  
  24. #define _KERNEL
  25. #include "ixemul.h"
  26. #include "kprintf.h"
  27. #include <stdlib.h>
  28.  
  29. int
  30. getpid(void)
  31. {
  32.   return (int)FindTask (0);
  33. }
  34.  
  35. int
  36. getppid(void)
  37. {
  38.   /* all processes have been started by init :-)) */
  39.   return 1;
  40. }
  41.  
  42. int
  43. setpgid(int pid, int pgrp)
  44. {
  45.   return pid==pgrp ? 0 : -1;
  46. }
  47.  
  48. int
  49. setpgrp(int pid, int pgrp)
  50. {
  51.   return setpgid(pid, pgrp);
  52. }
  53.  
  54. pid_t
  55. getpgrp(void)
  56. {
  57.   if (u.u_ixnetbase)
  58.     return netcall(NET_getpgrp);
  59.   return (int) FindTask(0);
  60. }
  61.  
  62. int
  63. getrusage(int who, struct rusage *rusage)
  64. {
  65.   if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
  66.     {
  67.       errno = EINVAL;
  68.       KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  69.       return -1;
  70.     }
  71.  
  72.   *rusage = (who == RUSAGE_SELF) ? u.u_ru : u.u_cru;
  73.   return 0;
  74. }
  75.  
  76. char hostname[64] = "localhost";
  77.  
  78. int
  79. gethostname(char *name, int namelen)
  80. {
  81.   if (u.u_ixnetbase)
  82.     return netcall(NET_gethostname, name, namelen);
  83.   strncpy (name, hostname, namelen);
  84.   return 0;
  85. }
  86.  
  87. int
  88. sethostname(char *name, int namelen)
  89. {
  90.   int len;
  91.  
  92.   if (u.u_ixnetbase)
  93.     return netcall(NET_sethostname, name, namelen);
  94.  
  95.   len = namelen < sizeof (hostname) - 1 ? namelen : sizeof (hostname) - 1;
  96.   strncpy (hostname, name, len);
  97.   hostname[len] = 0;
  98.   return 0;
  99. }
  100.  
  101. int
  102. __chown_func (struct StandardPacket *sp, struct MsgPort *handler,
  103.           BPTR parent_lock,
  104.           BSTR name,
  105.           int ugid, int *no_error)
  106. {
  107.   sp->sp_Pkt.dp_Type = ACTION_SET_OWNER;
  108.   sp->sp_Pkt.dp_Arg1 = 0;
  109.   sp->sp_Pkt.dp_Arg2 = parent_lock;
  110.   sp->sp_Pkt.dp_Arg3 = name;
  111.   sp->sp_Pkt.dp_Arg4 = ugid;
  112.  
  113.   PutPacket (handler, sp);
  114.   __wait_sync_packet (sp);
  115.  
  116.   *no_error = sp->sp_Pkt.dp_Res1 == -1;
  117.   return 1;
  118. }
  119.  
  120. int
  121.  
  122. chown(const char *name, uid_t uid, gid_t gid)
  123. {
  124.   if (muBase)
  125.     {
  126.       int user = (uid << 16) | gid;
  127.       int result;
  128.       result = __plock(name,__chown_func, (void *)user);
  129.       if (result == 0)
  130.     {
  131.       errno = __ioerr_to_errno (IoErr ());
  132.       KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  133.     }
  134.  
  135.       return result == -1 ? 0 : -1;
  136.    }
  137.   return 0;
  138. }
  139.  
  140. int
  141. fchown(int fd, int uid, int mode)
  142. {
  143.   return 0;
  144. }
  145.  
  146. /* not really useful.. but it's there ;-)) */
  147. int
  148. getpagesize(void)
  149. {
  150.   return 2048;
  151. }
  152.  
  153. extern char _ctype_[];
  154. extern int sys_nerr;
  155.  
  156. void
  157. ix_get_vars(char **ctype, int *_sys_nerr)
  158. {
  159.   if (ctype)
  160.     *ctype = _ctype_;
  161.   if (_sys_nerr)
  162.     *_sys_nerr = sys_nerr;
  163. }
  164.  
  165. void sync (void)
  166. {
  167.   /* could probably walk the entire file table and fsync each, but
  168.      this is too much of a nuisance ;-)) */
  169.   errno = ENOSYS;
  170.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  171. }
  172.  
  173. int
  174. fork (void)
  175. {
  176.   errno = ENOSYS;
  177.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  178.   return -1;
  179. }
  180.  
  181. int
  182. mkfifo (const char *path, mode_t mode)
  183. {
  184.   errno = ENOSYS;
  185.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  186.   return -1;
  187. }
  188.  
  189. int
  190. mknod (const char *path, mode_t mode, dev_t dev)
  191. {
  192.   errno = ENOSYS;
  193.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  194.   return -1;
  195. }
  196.  
  197.